#ifdef WIN32
#include <windows.h>
#endif

#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QSettings>

#include "WinRemocon.h"

#define APP_NAME	"WinRemocon"

int main(int argc, char *argv[])
{
#ifdef WIN32
	HANDLE mutex = CreateMutex(NULL, TRUE, TEXT(APP_NAME));
	if (GetLastError() == ERROR_ALREADY_EXISTS)
	{
		MessageBox(NULL, TEXT("Already running."), TEXT(APP_NAME), MB_OK | MB_ICONERROR);
		ReleaseMutex(mutex);
		CloseHandle(mutex);
		return -1;
	}
#endif
	
	QApplication app(argc, argv);
	
	app.setOrganizationName("atmark");
	app.setApplicationName(APP_NAME);
	app.setApplicationVersion("0.3.2");
	
	QTranslator qtTrans;
	qtTrans.load("qt_" + QLocale::system().name());
	app.installTranslator(&qtTrans);
	
	QTranslator appTrans;
	appTrans.load(QString("%1/translation_%2").arg(app.applicationDirPath()).arg(QLocale::languageToString(QLocale::system().language())));
	app.installTranslator(&appTrans);
	
	WinRemocon window;
	
	int ret = app.exec();
#ifdef WIN32
	ReleaseMutex(mutex);
	CloseHandle(mutex);
#endif
	return ret;
}
